package cn.home.sysmanagement.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.sysmanagement.domain.HomeTag;
import cn.home.sysmanagement.service.IHomeTagService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 健康标签Controller
 * 
 * @author homedoctor
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/sysmanagement/tag")
public class HomeTagController extends BaseController
{
    @Autowired
    private IHomeTagService homeTagService;

    /**
     * 查询健康标签列表
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeTag homeTag)
    {
        startPage();
        List<HomeTag> list = homeTagService.selectHomeTagList(homeTag);
        return getDataTable(list);
    }

    /**
     * 导出健康标签列表
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:export')")
    @Log(title = "健康标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeTag homeTag)
    {
        List<HomeTag> list = homeTagService.selectHomeTagList(homeTag);
        ExcelUtil<HomeTag> util = new ExcelUtil<HomeTag>(HomeTag.class);
        util.exportExcel(response, list, "健康标签数据");
    }

    /**
     * 获取健康标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homeTagService.selectHomeTagById(id));
    }

    /**
     * 新增健康标签
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:add')")
    @Log(title = "健康标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeTag homeTag)
    {
        //设置当前时间
        homeTag.setLasteditItime(new Date());
        System.out.println(new Date());
        //设置添加人
        homeTag.setAddPeople(getUsername());

        return toAjax(homeTagService.insertHomeTag(homeTag));
    }

    /**
     * 修改健康标签
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:edit')")
    @Log(title = "健康标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeTag homeTag)
    {
        return toAjax(homeTagService.updateHomeTag(homeTag));
    }

    /**
     * 删除健康标签
     */
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:remove')")
    @Log(title = "健康标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homeTagService.deleteHomeTagByIds(ids));
    }

    //通过医生的id查询医生的标签
    @PreAuthorize("@ss.hasPermi('sysmanagement:tag:query')")
    @GetMapping(value = "/doctor/{id}")
    public AjaxResult getInfoByDoctorId(@PathVariable("id") Long id)
    {
        return success(homeTagService.selectHomeTagByDoctorId(id));
    }


}
